/*
 * Copyright 2008 Karel Klic.
 * This file is part of Oslavanský Bot.
 * 
 * Oslavanský Bot is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
package categorybot;

import java.util.*;

/**
 *
 * @author Karel
 */
public class EditorSummaryBuilder {
  
  private List<SolveCategoryResult> list;
  
  public EditorSummaryBuilder(List<SolveCategoryResult> list) {
    this.list = list;
  }
  
  @Override
  public String toString() {
    ArrayList<SolveCategoryResult> added = new ArrayList<SolveCategoryResult>();
    ArrayList<SolveCategoryResult> removed = new ArrayList<SolveCategoryResult>();
    for (SolveCategoryResult result : list) {
      switch (result.getChangeType()) {
        case Add:
          added.add(result);
          break;
        case Remove:
          removed.add(result);
          break;
      }
    }
    
    StringBuilder builder = new StringBuilder("robot ");
    
    if (added.size() > 0) {
      builder.append("přidal: ");
      for (int i = 0; i < added.size(); ++i) {
        builder.append(added.get(i).getCategoryLink());
        if (i != added.size() - 1) {
          builder.append(", ");
        }
      }
    }
    
    if (removed.size() > 0) {
      if (added.size() > 0) {
       builder.append("; ");
      }
        
      builder.append("odebral: ");
      for (int i = 0; i < removed.size(); ++i) {
        builder.append(removed.get(i).getCategoryLink());
        if (i != removed.size() - 1) {
          builder.append(", ");
        }
      }
    } 
    
    return builder.toString();
  }
}
